/**
 * 微信本地存储服务
 */
//默认缓存时间
const cacheExpire = 7200;

module.exports = {
  get: function (Cache_KEY) {
    let timestamp = Date.parse(new Date());
    let cachedata = wx.getStorageSync(Cache_KEY);
    if (cachedata && cachedata.data){
      if (cachedata.expire > timestamp){
        //console.log(Cache_KEY + '存在', cachedata);
        return cachedata.data;
      }else{
        //console.log(Cache_KEY + '已过期');
        wx.removeStorageSync(Cache_KEY);
      }
    }
    return null;
  },

  set: function (Cache_KEY, Cache_data, expire = cacheExpire) {
    let timestamp = Date.parse(new Date());
    let cachedata = { 'data': Cache_data, 'expire': timestamp + expire * 1000 };
    wx.setStorageSync(Cache_KEY, cachedata);
  },

  del: function () {
    wx.removeStorageSync(Cache_KEY);
  },

  clear: function () {
    wx.clearStorage();
  },
};